package com.cjh.controller;


import com.cjh.annotation.WebLog;
import com.cjh.dto.LoginDto;
import com.cjh.entity.User;
import com.cjh.service.LoginService;
import com.cjh.service.UserService;
import com.cjh.utils.RedisUtil;
import com.cjh.utils.ResultJson;
import com.cjh.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cjh
 * @since 2021-12-26
 */
@RestController
@RequestMapping("/user")
@Api(tags = "用户控制器")
@Slf4j
public class UserController {

    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    @WebLog(description = "登录接口")
    @ApiOperation("登录接口")
    public ResultJson<LoginVo> login(@RequestBody LoginDto loginDto){

        return loginService.login(loginDto);
    }

    @GetMapping("/logout")
    @WebLog(description = "注销接口")
    @ApiOperation("注销接口")
    public ResultJson logout(){

        return loginService.logout();
    }

    @GetMapping("/hello")
//    @PreAuthorize("hasAnyAuthority('system:customer:list')")
    //使用自定义方法
//    @PreAuthorize("@mySecurityExpressionRoot.hasAuthority('system:customer:list')")
    @WebLog(description = "hello接口")
    public ResultJson hello(){

        return ResultJson.ok(200,"ok","hello");
    }
}

